


class Solution:
    ans = 1
    def diameterOfBinaryTree(self, root):
        # ans = 1
        def depth(root):
            # nonlocal ans
            if not root: return 0

            L = depth(root.left) + 1
            R = depth(root.right) + 1

            self.ans = max(self.ans, L + R - 1)

            # return ans
            return max(L, R)
        depth(root)
        return self.ans - 1